package alpaca.view.panels;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class ErrorDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private final Action action = new OK();


	/**
	 * Create the dialog.
	 * @param point 
	 */
	public ErrorDialog(String error, Point point) {
		setAlwaysOnTop(true);
		setIconImage(new ImageIcon("img//alpaca.png").getImage());
		getContentPane().setLayout(new BorderLayout(0, 0));
		getContentPane().add(contentPanel);
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		JLabel errorLabel = new JLabel(error);
		contentPanel.add(errorLabel);
		setBounds(point.x, point.y, 387, 155);

		{
			JPanel buttonPane = new JPanel();
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
			{
				JButton okButton = new JButton("OK");
				okButton.setAction(action);
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
		pack();
		}
	}

	private class OK extends AbstractAction {
		public OK() {
			putValue(NAME, "OK");
		}
		@Override
		public void actionPerformed(ActionEvent e) {
			dispose();
		}
	}
}
